package com.task.manage.system.controller;


import com.task.manage.common.annotation.Log;
import com.task.manage.common.core.controller.BaseController;
import com.task.manage.common.core.domain.AjaxResult;
import com.task.manage.common.core.page.TableDataInfo;
import com.task.manage.common.enums.BusinessType;
import com.task.manage.common.utils.poi.ExcelUtil;
import com.task.manage.system.domain.MerchantInfo;
import com.task.manage.system.domain.resp.MerchantStatisticsResp;
import com.task.manage.system.service.IMerchantInfoService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * 数据统计
 */
@Controller
@RequestMapping("/system/statistics")
public class StatisticsController extends BaseController {


    @Resource
    private IMerchantInfoService merchantInfoService;

    private String prefix = "system/statistics";

    @RequiresPermissions("system:statistics:view")
    @GetMapping()
    public String info() {
        return prefix + "/statistics";
    }


    /**
     * 商家数据统计查询列表
     * @param merchantInfo
     * @return
     */
    @RequiresPermissions("system:statistics:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(MerchantInfo merchantInfo) {
        startPage();
        List<MerchantStatisticsResp> list = merchantInfoService.selectMercStatisticsList(merchantInfo);
        return getDataTable(list);
    }


    /**
     * 导出商家数据统计数据
     * @param
     * @return
     */
    @RequiresPermissions("system:statistics:export")
    @Log(title = "任务管理器", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MerchantInfo merchantInfo) {
        List<MerchantStatisticsResp> list = merchantInfoService.selectMercStatisticsList(merchantInfo);
        ExcelUtil<MerchantStatisticsResp> util = new ExcelUtil<MerchantStatisticsResp>(MerchantStatisticsResp.class);
        return util.exportExcel(list, "商家数据统计");
    }
}
